#include <iostream>
#include <string>
using namespace std;

typedef struct word_in
{
    string word;
    int times=1;
}wordin;

void StringSet(wordin words[100])
{
    int i;
    for(i=0;;i++)
    {
        cin>>words[i].word;
        if(words[i].word=="0")
            break;
    }
}

void FindRepeat(wordin words[100],int n)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=i-1;j>=0;j--)
        {
            if(words[j].word==words[i].word)
            {
                words[i].times=words[j].times;
                goto END;
            }
        }
        for(j=i+1;j<n;j++)
        {
            if(words[j].word==words[i].word)
                words[i].times++;
        }
        END:;
    }
}

void OutWords(wordin words[100],int n)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=i-1;j>=0;j--)
        {
            if(words[j].word==words[i].word)
                goto END;
        }
        cout<<words[i].word<<"  "<<words[i].times<<endl;
        END:;
    }
}

int main()
{
    int i;
    string str[1000];
    wordin words[100];
    StringSet(words);
    for(i=0;words[i].word!="0";i++);
    int n=i;
    FindRepeat(words,n);
    OutWords(words,n);
    return 0;
}
